package com.eBook.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eBook.dao.BookDao;
import com.eBook.dao.CommentDao;
import com.eBook.dao.UserDao;
import com.eBook.entity.Book;
import com.eBook.entity.Comment;
import com.eBook.entity.User;
import com.eBook.service.CommentService;

@Service
public class CommentServiceImpl implements CommentService{
	@Autowired
	private CommentDao cDao;
	@Autowired
	private UserDao uDao;
	@Autowired
	private BookDao bDao;
	@Override
	public List<Comment> findAllCommentsByBookId(int id) {
		List<Comment> testComments = cDao.findAllCommentsByBookId(id);
		
		return testComments;
	}
	@Override
	public void addComment(int bookId,int userId,String content) {
		User user = uDao.findUserById(userId);
		Map<String, String> map = new HashMap<String, String>();
		map.put("commentUser", userId+"");
		map.put("commentBook", bookId+"");
		map.put("commentContent", content);
		cDao.addComment(map);
	}

}
